/**
 * @fileoverview Models for Inspectres! Live!
 *
 * TODO(jlapenna): I forget how construtors work. These modles are fucked as
 * their attributes don't exist until they are setXYZ().
 *
 * TODO(jlapenna): adjust calls don't work if setXZY hasn't already been made.
 */

models = {};

/**
 * The confessional.
 */
models.Confessional = function() {

  /**
   * Stores which participant is the confessor.
   * @type {Boolean}
   */
  this.confessor_ = null;

  models.Confessional.prototype.getConfessor = function() {
    return this.confessor_;
  };

  models.Confessional.prototype.setConfessor = function(confessor) {
    this.confessor_ = confessor;
    return this;
  };

  models.Confessional.prototype.serialize = function() {
    var confessional = {
      'confessor': this.confessor_
    };
    return JSON.stringify(confessional);
  }

  models.Confessional.fromJSON = function(json) {
    var parsed = JSON.parse(json);
    return new models.Confessional()
        .setConfessor(parsed.confessor);
  };
}


/**
 * A participant in the game.
 */
models.Participant = function() {

  /**
   * The hangout participant id of the user represented.
   */
  this.id_ = null;

  /**
   * Stores if the user is a confessor.
   * @type {Boolean}
   */
  this.confessor_ = null;

  models.Participant.prototype.setId = function(id) {
    this.id_ = id;
    return this;
  };

  models.Participant.prototype.getId = function() {
    return this.id_;
  };

  models.Participant.prototype.setConfessor = function(isConfessor) {
    this.isConfessor_= isConfessor;
    return this;
  };

  /**
   * If the participant is a confessor.
   */
  models.Participant.prototype.isConfessor = function() {
    return this.isConfessor_;
  };

  models.Participant.prototype.serialize = function() {
    var participant = {
      'id': this.id_,
      'is_confessor': this.isConfessor_
    };
    return JSON.stringify(participant);
  }

  models.Participant.fromJSON = function(json) {
    var parsed = JSON.parse(json);
    return new models.Participant()
        .setId(parsed.id)
        .setConfessor(parsed.is_confessor);
  };
};

/**
 * A franchise and a team.
 */
models.Team = function() {

  /**
   * The franchise the team is a part of
   * @type {Franchise}
   */
  this.franchise_ = null;

  /**
   * The active team members.
   * @type {Array<Character>}
   */
  this.characters_ = [];

  models.Team.prototype.setFranchise = function(franchise) {
    this.franchise_ = franchise;
    return this;
  };

  models.Team.prototype.addCharacter = function(character) {
    this.characters_ = this.characters_.concat([character]);
    return this;
  }
};


/**
 * Information about a character in a franchise.
 */
models.Character = function() {

  /**
   * Name.
   * @type {String}
   */
  this.name_ = null;

  /**
   * Talent.
   * @type {String}
   */
  this.talent_ = null;

  /**
   * Biography.
   * @type {String}
   */
  this.biography_ = null;

  /**
   * Academics score.
   * @type {Number}
   */
  this.academics_ = 0;

  /**
   * Athletics score.
   * @type {Number}
   */
  this.athletics_ = 0;

  /**
   * Technology score.
   * @type {Number}
   */
  this.technology_ = 0;

  /**
   * Contact score.
   * @type {Number}
   */
  this.contact_ = 0;

  /**
   * Cool score.
   * @type {Number}
   */
  this.cool_ = 0;

  models.Character.prototype.getName = function() {
    return this.name_;
  };

  models.Character.prototype.setName = function(name) {
    this.name_ = name;
    return this;
  };

  models.Character.prototype.getTalent = function() {
    return this.talent_;
  };

  models.Character.prototype.setTalent = function(talent) {
    this.talent_ = talent;
    return this;
  };

  models.Character.prototype.getBiography = function() {
    return this.biography_;
  };

  models.Character.prototype.setBiography = function(biography) {
    this.biography_ = biography;
    return this;
  };

  models.Character.prototype.getAcademics = function() {
    return this.academics_;
  };

  models.Character.prototype.setAcademics = function(academics) {
    this.academics_ = academics;
    return this;
  };

  models.Character.prototype.adjustAcademics = function(count) {
    this.academics_ += count;
    return this;
  };

  models.Character.prototype.getAthletics = function() {
    return this.athletics_;
  };

  models.Character.prototype.setAthletics = function(athletics) {
    this.athletics_ = athletics;
    return this;
  };

  models.Character.prototype.adjustAthletics = function(count) {
    this.athletics_ += count;
    return this;
  };

  models.Character.prototype.getTechnology = function() {
    return this.technology_;
  };

  models.Character.prototype.setTechnology = function(technology) {
    this.technology_ = technology;
    return this;
  };

  models.Character.prototype.adjustTechnology = function(count) {
    this.technology_ += count;
    return this;
  };

  models.Character.prototype.getContact = function() {
    return this.contact_;
  };

  models.Character.prototype.setContact = function(contact) {
    this.contact_ = contact;
    return this;
  };

  models.Character.prototype.adjustContact = function(count) {
    this.contact_ += count;
    return this;
  };

  models.Character.prototype.getCool = function() {
    return this.cool_;
  };

  models.Character.prototype.setCool = function(cool) {
    this.cool_ = cool;
    return this;
  };

  models.Character.prototype.adjustCool = function(count) {
    this.cool_ += count;
    return this;
  };

  models.Character.prototype.serialize = function() {
    var character = {
      'name': this.name_,
      'talent': this.talent_,
      'biography': this.biography_,
      'academics': this.academics_,
      'athletics': this.athletics_,
      'technology': this.technology_,
      'contact': this.contact_,
      'cool': this.cool_
    };
    return JSON.stringify(character);
  }

  models.Character.fromJSON = function(json) {
    var parsed = JSON.parse(json);
    return new models.Character()
        .setName(parsed.name)
        .setTalent(parsed.talent)
        .setBiography(parsed.biography)
        .setAcademics(parsed.academics)
        .setAthletics(parsed.athletics)
        .setTechnology(parsed.technology)
        .setContact(parsed.contact)
        .setCool(parsed.cool);
  };
};


/**
 * Information about a franchise.
 */
models.Franchise = function() {

  /**
   * Name of the franchise.
   * @type {String}
   * @private
   */
  this.name_ = null;

  /**
   * Gym score.
   * @type {Number}
   * @private
   */
  this.gym_ = 0;

  /**
   * Credit score.
   * @type {Number}
   * @private
   */
  this.credit_ = 0;

  /**
   * Library score.
   * @type {Number}
   * @private
   */
  this.library_ = 0;

  /**
   * Bank account size.
   * @type {Number}
   * @private
   */
  this.bank_ = 0;

  models.Franchise.prototype.getName = function() {
    return this.name_;
  };

  models.Franchise.prototype.setName = function(name) {
    this.name_ = name;
    return this;
  };

  models.Franchise.prototype.getGym = function() {
    return this.gym_;
  };

  models.Franchise.prototype.setGym = function(gym) {
    this.gym_ = gym;
    return this;
  };

  models.Franchise.prototype.adjustGym = function(count) {
    this.gym_ += count;
    return this;
  };

  models.Franchise.prototype.getCredit = function() {
    return this.credit_;
  };

  models.Franchise.prototype.setCredit = function(credit) {
    this.credit_ = credit;
    return this;
  };

  models.Franchise.prototype.adjustCredit = function(count) {
   this.credit_ += count;
    return this;
  };

  models.Franchise.prototype.getLibrary = function() {
    return this.library_;
  };

  models.Franchise.prototype.setLibrary = function(library) {
    this.library_ = library;
    return this;
  };

  models.Franchise.prototype.adjustLibrary = function(count) {
    this.library_ += count;
    return this;
  };

  models.Franchise.prototype.getBank = function() {
    return this.bank_;
  };

  models.Franchise.prototype.setBank = function(bank) {
    this.bank_ = bank;
    return this;
  };

  models.Franchise.prototype.adjustBank = function(count) {
    this.bank_ += count;
    return this;
  };

  models.Franchise.prototype.serialize = function() {
    var franchise = {
      'name': this.name_,
      'gym': this.gym_,
      'credit': this.credit_,
      'library': this.library_,
      'bank': this.bank_
    };
    return JSON.stringify(franchise);
  }

  models.Franchise.fromJSON = function(json) {
    var parsed = JSON.parse(json);
    return new models.Franchise()
      .setName(parsed.name)
      .setGym(parsed.gym)
      .setCredit(parsed.credit)
      .setLibrary(parsed.library)
      .setBank(parsed.bank);
  };
};
